package com.hxkj.controller;

import com.alibaba.fastjson.JSONObject;
import com.hxkj.entity.enums.FilePathEnum;
import com.hxkj.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.concurrent.Callable;

/**
 * 文件上传控制层
 * <p>
 * Created by zzx on 2018/6/20.
 */
@RestController
@RequestMapping("/file")
public class FileController {

    @Autowired
    private FileService fileService;
    /**
     * 批量图片上传
     *
     * @param file 图片信息   第二个参数为自定义一个 存放文件的目录名称
     * @throws Exception
     */

    @RequestMapping(value = "/testupload", method = RequestMethod.POST)
    public Callable<List<String>> imgUpload(@RequestParam(value = "file", required = false) MultipartFile [] file) throws Exception {
        return () -> fileService.fileUpload(file, FilePathEnum.IMG_FILE_PATH.getDescription());
    }

    /**
     * 友情链接网站log
     */
    @RequestMapping(value = "/friendlylinkupload", method = RequestMethod.POST)
    public Callable<List<String>> imgUploadFriendlyLink(@RequestParam(value = "file", required = false) MultipartFile [] file) throws Exception {
        return () -> fileService.fileUpload(file, FilePathEnum.FRIENDLYLINK_FILE_PATH.getDescription());
    }


    /**
    * @author Mr.zheng
    * @Description templetUploud 模板上传
    * @Date 8:55 2018/6/8
    * @Param [file]
    * @return java.util.concurrent.Callable<java.util.List<java.lang.String>>
    **/
    @RequestMapping(value = "/templetupload", method = RequestMethod.POST)
    public Callable<List<String>> templetUploud(@RequestParam(value = "file", required = false) MultipartFile [] file) throws Exception {
        return () -> fileService.templetUploud(file, FilePathEnum.TEMPLET_FILE_PATH.getDescription());
    }

    /**
     * 小程序图片上传
     */
    @RequestMapping(value = "/appletUpload", method = RequestMethod.POST)
    public Callable<List<String>> appletUpload(@RequestParam(value = "file", required = false) MultipartFile []  file) throws Exception {
        return () -> fileService.appletUpload(file, FilePathEnum.IMG_FILE_PATH.getDescription());
    }

    /**
     * 小程序图片上传
     */
    @RequestMapping(value = "/articleUpload", method = RequestMethod.POST)
    public Callable<List<String>> AppletFileUpload(@RequestParam(value = "file", required = false) MultipartFile [] file) throws Exception {
        return () -> fileService.AppletFileUpload(file, FilePathEnum.IMG_FILE_PATH.getDescription());
    }

    /**
     * 测试压缩图片
     *
     * @param file 图片信息   第二个参数为自定义一个 存放文件的目录名称
     * @throws Exception
     */
    @RequestMapping(value = "/imgupload", method = RequestMethod.POST)
    public String imgUpload(@RequestParam(value = "file", required = false) MultipartFile  file) throws Exception {
        return fileService.imgUpload(file, FilePathEnum.IMG_FILE_PATH.getDescription());
    }


    /**
     * ueditor  图片上传
     *
     * @param file 图片信息   第二个参数为自定义一个 存放文件的目录名称
     * @throws Exception
     */
    @RequestMapping(value = "/ueditorimgupload", method = RequestMethod.POST)
    public Callable<JSONObject> ueditorimgupload(@RequestParam(value = "file", required = false) MultipartFile  file,
                                                 @RequestParam(value = "action", required = false) String action) {
        return () ->  fileService.ueditorimgupload(file, FilePathEnum.IMG_FILE_PATH.getDescription(),action);
    }
    /**
     * 导航栏缩略图
     */
    @RequestMapping(value = "/navigationimgupload", method = RequestMethod.POST)
    public Callable<List<String>> imgUploadNavigationImg(@RequestParam(value = "file", required = false) MultipartFile [] file) {
        return () -> fileService.fileUpload(file, FilePathEnum.NAVIGATION_IMG_FILE_PATH.getDescription());
    }


    /**
     * 通用文件上传
     */
    @RequestMapping(value = "/commonUpload")
    public Callable<JSONObject> commonUpload(@RequestParam(value = "file", required = false) MultipartFile file,
                                                         HttpServletRequest request) {
        return () -> fileService.commonUpload(file, request);
    }


}
